package database.viewer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;

import database.table.DBTableData;

public class CommandPanel extends JPanel {
	private JButton		buttonLoad;
	private JButton		buttonLoadAll;
	private JButton		buttonGroup;
	private JButton		buttonPropagate;
	private JButton		buttonCommit;
	private JPanel		buttonPanel;
	
	private ActionListener control;
	
	public CommandPanel( ActionListener control ) {
		GridBagConstraints constraints = new GridBagConstraints();
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		setBorder( new EmptyBorder(5, 5, 5, 5));
		
		this.control = control;
		
		// Setup button panels
		buttonPanel = new JPanel();
		buttonPanel.setLayout(new GridBagLayout());
		
		constraints.fill = GridBagConstraints.BOTH;
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.weightx = 1.0;
		constraints.weighty = 0.0;
		
		buttonLoad = new JButton("Load table");
		buttonLoad.setActionCommand(DBTableViewer.COMMAND_LOADTABLE);
		buttonLoad.addActionListener(control);
		buttonLoad.setMnemonic('l');
		buttonPanel.add(buttonLoad, constraints);
		
		buttonLoadAll = new JButton("Load all tables");
		buttonLoadAll.setActionCommand(DBTableViewer.COMMAND_LOADTABLEALL);
		buttonLoadAll.addActionListener(control);
		buttonLoadAll.setMnemonic('a');
		constraints.gridy++;
		buttonPanel.add(buttonLoadAll, constraints);
		
		buttonGroup = new JButton("Group elements");
		buttonGroup.setActionCommand(DBTableViewer.COMMAND_GROUPELEMENTS);
		buttonGroup.addActionListener(control);
		buttonGroup.setMnemonic('g');
		constraints.gridy++;
		buttonPanel.add(buttonGroup, constraints);
		
		buttonPropagate = new JButton("Propagate 'chars'");
		buttonPropagate.setActionCommand(DBTableViewer.COMMAND_PROPAGATE);
		buttonPropagate.addActionListener(control);
		buttonPropagate.setMnemonic('p');
		constraints.gridy++;
		buttonPanel.add(buttonPropagate, constraints);
		
		buttonCommit = new JButton("Commit table to database");
		buttonCommit.setActionCommand(DBTableViewer.COMMAND_COMMIT);
		buttonCommit.addActionListener(control);
		buttonCommit.setMnemonic('c');
		constraints.gridy++;
		buttonPanel.add(buttonCommit, constraints);
		
		// Add panels
		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.weightx = 1.0;
		constraints.weighty = 0.0;
		add(buttonPanel);//, constraints);
		
		//constraints.gridx = 0;
		//constraints.gridy = 1;
		//constraints.weightx = 1.0;
		//constraints.weighty = 1.0;
		//add(new JPanel(), constraints);
	}
}
